// pages/discount/discount.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    act_item_list: null, //折扣商品列表
    baseImgURL:'https://jrtest.0791jr.com/data/attachment/item/',
    //为空提示
    isNone: false,
    emptyTip: {
      font: "暂时还没有特价活动哦~",
      imgUrl: "https://jrtest.0791jr.com/WeChat/images/empty-offer.png"
    },
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    wx.showLoading({ title: '加载中', mask: true })
    //获取特价商品的数据
    wx.request({
      url: app.baseURL + 'Index&a=bargain&user_id=' + app.globalData.userId,
      success: (res) => {
        if (res.statusCode == 200) {
          let data = res.data;
          this.setData({ 
            act_item_list: data.act_item_list,
            banner: data.hb,
            isNone: !data.act_item_list.length  
          });
          wx.hideLoading();
        }
      },
      'fail': (res) => {
        wx.showToast({ title: '网络错误，请稍后重试', icon: 'none' })
      }
    });
  },

  // 跳转详情页
  clickToDetail(e){
    const itemId = e.currentTarget.dataset.item_id;
    const gui_id = e.currentTarget.dataset.guiid_id;
    const hd_id = e.currentTarget.dataset.hd_id;
    wx.navigateTo({
      url: '/pages/detail/detail?type=2&item_id=' + itemId + '&gui_id=' + e.currentTarget.dataset.guiid_id + '&act_id=' + e.currentTarget.dataset.hd_id,
    })
  }
})